---
id: http-call
title: HTTP Call Node
sidebar_label: HTTP Call
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

![HTTP Call Node Screenshot](./assets/http-call-node.png)

## Overview

The HTTP Call Node allows you to make an HTTP call to a specified URL with a given method, headers, and body. This node is particularly useful when you need to interact with external APIs or services.

The HTTP Call Node uses the Fetch API to make HTTP requests. It supports all HTTP methods (GET, POST, PUT, DELETE, etc.) and allows you to specify custom headers and a request body.

:::caution
When using the default [browser executor](../user-guide/executors.md), you have to worry about [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) when making HTTP requests to external APIs. If the API you are trying to call does not support CORS to `http://tauri.local` (most do not), you will run into CORS problems. This can manifest as an error `fetch failed` in the output panel.

This can be worked around by using the [Node executor](../user-guide/executors.md) in Rivet, which does not do CORS checks.
:::

<Tabs
  defaultValue="inputs"
  values={[
    {label: 'Inputs', value: 'inputs'},
    {label: 'Outputs', value: 'outputs'},
    {label: 'Editor Settings', value: 'settings'},
  ]
}>

<TabItem value="inputs">

## Inputs

The HTTP call node only has inputs when the [Editor Settings](#editor-settings) are set to use input toggles. See that section for more information.

</TabItem>

<TabItem value="outputs">

## Outputs

| Title       | Data Type | Description                                                                             | Notes                                                                   |
| ----------- | --------- | --------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |
| Body        | `string`  | The body of the HTTP response.                                                          | If the response body is not a string, this output will not be ran.      |
| JSON        | `object`  | If the response body is a JSON object, this output will contain the parsed JSON object. | If the response body is not a JSON object, this output will not be ran. |
| Status Code | `number`  | The status code of the HTTP response.                                                   |                                                                         |
| Headers     | `object`  | The headers of the HTTP response.                                                       |                                                                         |

</TabItem>

<TabItem value="settings">

## Editor Settings

| Setting                      | Description                                                                                                                                                                                         | Default Value | Use Input Toggle | Input Data Type |
| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- | ---------------- | --------------- |
| Method                       | The HTTP method to use for the request (GET, POST, PUT, DELETE, etc.).                                                                                                                              | GET           | Yes              | `string`        |
| URL                          | The URL to make the HTTP request to.                                                                                                                                                                | (empty)       | Yes              | `string`        |
| Headers                      | An object representing the headers to include in the HTTP request.                                                                                                                                  | (empty)       | Yes              | `object`        |
| Body                         | The body of the HTTP request. This is typically used for POST or PUT requests. The value passed in here is not JSON stringified, so if you need a JSON body, use the [To JSON](./to-json.mdx) node. | (empty)       | Yes              | `string`        |
| Error on non-200 status code | If enabled, the node will error if the status code of the HTTP response is not 200.                                                                                                                 | True          | No               | N/A             |

</TabItem>

</Tabs>

## Example 1: Make a GET request to an API

1. Create an HTTP Call Node and set the `Method` to `GET` and the `URL` to `https://jsonplaceholder.typicode.com/todos/1`.
2. Run the graph. You should see all of the response data, such as the headers, response code, and body, in the output panel.

![HTTP Call Node Example 1](./assets/http-call-node-example-01.png)

## Example 2: Make a POST request to an API

1. Create an HTTP Call Node and set the `Method` to `POST` and the `URL` to `https://jsonplaceholder.typicode.com/posts`. Enable the "Use Input" toggle on the "Body" setting to enable the input port for Body.
2. Create an [Object Node](./object.mdx) and set the object to:

```json
{
  "title": "foo",
  "body": "bar",
  "userId": 1
}
```

3. Create a [To JSON Node](./to-json.mdx) and connect the Object Node to the `Data` input of the To JSON Node. Connect the To JSON Node to the `Body` input of the HTTP Call Node.
4. Create an [Extract Object Path](./extract-object-path.mdx) Node and connect the `JSON` output of the HTTP Call Node to the `Object` input of the Extract Object Path Node. Set the `Path` to `$.id`.
5. Run the graph. You should see the created ID of the post in the Extract Object Path Node's output panel.

![HTTP Call Node Example 2](./assets/http-call-node-example-02.png)

## Error Handling

The HTTP Call Node will error if the HTTP request fails for any reason, such as a network error or if the server returns an error status code. If the `Error on non-200 status code` setting is enabled, the node will also error if the status code of the HTTP response is not 200.

## FAQ

**Q: Can I use the HTTP Call Node to make requests to any API?**

A: Yes, you can use the HTTP Call Node to make requests to any API that supports the HTTP methods GET, POST, PUT, or DELETE.

**Q: Can I use the HTTP Call Node to send JSON in the request body?**

A: Yes, you can use a [Text Node](./text.mdx) to create a JSON string and connect it to the `Body` input of the HTTP Call Node.

**Q: Can I use the HTTP Call Node to handle API authentication?**

A: Yes, you can include authentication headers in the `Headers` input of the HTTP Call Node. However, for security reasons, you should not hardcode sensitive information like API keys in your graphs. Instead, consider using a [Context Node](./context.mdx) to securely pass in sensitive information from the host application.

## See Also

- [To JSON Node](./to-json.mdx)
- [Extract JSON Node](./extract-json.mdx)
- [Extract Object Path Node](./extract-object-path.mdx)
- [Text Node](./text.mdx)
- [Context Node](./context.mdx)
